<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>采购药品</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css">

</head>
<body style="background-color:#fff;">
<div class="layui-fluid">
    <!-- 添加 -->
    <div class="layui-row">
        <fieldset class="layui-elem-field site-demo-button layui-col-md-offset2 layui-col-md8"
                  style="margin-top: 30px;padding:15px;">
            <legend>药品信息入库</legend>
            <form class="layui-form layui-form-pane" lay-filter="add-drug" id="addForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">药品名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" autocomplete="off" placeholder="请填写药品名"
                                   class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">规格</label>
                        <div class="layui-input-block">
                            <input type="text" name="spec" autocomplete="off" placeholder="请填写规格"
                                   class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="unit" autocomplete="off" placeholder="请填写单位"
                                   class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">生产企业</label>
                        <div class="layui-input-block">
                            <input type="text" name="product_company" autocomplete="off" placeholder="请填写生产企业"
                                   class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">生产日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="product_date" id="productDate" placeholder="请填写生产日期"
                                   autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">保质期至</label>
                        <div class="layui-input-block">
                            <input type="text" name="ok_date" id="okDate" placeholder="请填写保质期至"
                                   autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">进价</label>
                        <div class="layui-input-block">
                            <input type="text" name="import_price" autocomplete="off" placeholder="请填写进价"
                                   class="layui-input" lay-verify="required|number">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">零售价</label>
                        <div class="layui-input-block">
                            <input type="text" name="price" autocomplete="off" placeholder="请填写零售价"
                                   class="layui-input" lay-verify="required|number">
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">销售状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="sale_status" value="0" title="是" checked="">
                            <input type="radio" name="sale_status" value="1" title="否">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">是否进口</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_import" value="0" title="是" checked="">
                            <input type="radio" name="is_import" value="1" title="否">
                        </div>
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">产品说明</label>
                    <div class="layui-input-block">
                    <textarea placeholder="请填写产品说明" class="layui-textarea"
                              name="description"></textarea>
                    </div>
                </div>
                <div class="layui-form-item" style="text-align: center;">
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit="" lay-filter="add-drug">添加药品</button>
                    </div>
                </div>
            </form>
        </fieldset>
    </div>
</div>

<script src="../../../layui/layui.js"></script>
<script>
    layui.use(['form', 'laydate'], function () {
        var $ = layui.$; // 注册 jquery 组件
        var form = layui.form;// 注册 form 组件
        var laydate = layui.laydate;// 注册 laydate 组件

        //生产日期
        laydate.render({
            elem: '#productDate'
        });
        //保质期至
        laydate.render({
            elem: '#okDate'
        });
        //采购药品表单提交
        form.on('submit(add-drug)', function (data) {
            $.ajax({
                url:'/springboot-hospital/drug/add',
                data:$('#addForm').serialize(),
                success:function (result) {
                    if(result.flag){
                        layer.msg('添加成功');
                        $('#addForm')[0].reset();
                        location.href='DrugsList.html';
                    }else{
                        layer.msg('添加失败')
                    }
                }
            })
            return false;
        });

    })
</script>
</body>
</html>
